<div class="hide-print">
<div>包含票据报销单</div>
<?php
$expenses=$model->materialExpenses;
$totalExpense=0;
foreach ($expenses as $expense){
	$totalExpense+=$expense->totalPrice;
}
$this
->widget('zii.widgets.grid.CGridView',
	array(
		'id' => 'account-token-grid',
		'dataProvider' => new CArrayDataProvider($expenses),
		'columns' => array(
			//'id',
			array(
				'header' => '报销日期',
				'name'=>'expenseDate'
			),
			array(
				'header' => '项目',
				'name'=>'project.name'
			),
			array(
				'header' => '包含票据',
				'value'=>'$data->materialReceiptsCount'
			),
			array(
				'header' => '总额',
				'name'=>'totalPrice',
				'type'=>'currency',
				'footer'=>Yii::app()->format->formatCurrency($totalExpense),
			),
			array(
				'header' => '经办',
				'name'=>'createUser.employee.fullName',
			),
			array(
				'header' => '生成日期',
				'name'=>'createTime'
			),
			array(
				'class' => 'CButtonColumn',
				'template'=>'{delete}',
				'deleteButtonUrl'=>'Yii::app()->controller->createUrl("detachMaterialExpense",array("materialExpenseId"=>$data->primaryKey))',
				'deleteButtonOptions'=>array(
					'class'=>'delete',
				)
			),
		),
	));
?>
<div class="form">
<?php $form = $this
	->beginWidget('CActiveForm',
		array(
			'id' => 'account-token-scan-expense',
			'enableAjaxValidation' => false,
			'focus'=>'input[name=code]'
		));
?>

	<div class="row">
		<label>扫描添加</label>
		<?php echo CHtml::textField('code','',array('id'=>'scan-material-expense-code')); ?>
		<?php echo CHtml::hiddenField('accountTokenId', $model->id); ?>
		<?php echo CHtml::submitButton('查找'); ?>
	</div>

<?php $this->endWidget(); ?>
<?php 
$url=CJSON::encode($this->createUrl('findAttachExpense'));
$script=<<<EOF
(function($){
	var form=$("#account-token-scan-expense");
	var loading='查找中...';
	form.submit(function(){
		if($("#scan-material-expense-code").val()){
			var formData=form.serialize();
			var target=$("#expense-scan-result");
		    target.html(loading);
		    jQuery.post( $url, formData,function(data){
		        target.html(data);
		        }, 'html' );
	    }
	    return false;
	});
})(jQuery);
EOF;
Yii::app()->clientScript->registerScript('account-token-scan', $script);
?>
</div>
<div id="expense-scan-result">

</div>
</div>